package com.mwt.oes.service.impl;

import com.mwt.oes.dao.BankSingleChoiceQueMapper;
import com.mwt.oes.dao.QuestionMapper;
import com.mwt.oes.dao.StudentPaperAnswerMapper;
import com.mwt.oes.domain.BankSingleChoiceQue;
import com.mwt.oes.domain.Question;
import com.mwt.oes.service.QuestionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author caiwl
 * @date 2023/10/25 21:41
 */
@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private BankSingleChoiceQueMapper singleQuestionMapper;
    @Autowired
    private StudentPaperAnswerMapper studentPaperAnswerMapper;

    @Override
    public List<Question> selectList(String singleContent) {
        return questionMapper.selectList(singleContent);
    }

    @Override
    public int insertOne(Question question) {
        BankSingleChoiceQue bankSingleChoiceQue = new BankSingleChoiceQue();
        BeanUtils.copyProperties(question, bankSingleChoiceQue);
        singleQuestionMapper.insertSelective(bankSingleChoiceQue);
        question.setSingleId(bankSingleChoiceQue.getSingleId());
        return questionMapper.insertOne(question);
    }

    @Override
    public int updateOne(Question question) {
        BankSingleChoiceQue bankSingleChoiceQue = new BankSingleChoiceQue();
        BeanUtils.copyProperties(question, bankSingleChoiceQue);
        int singleQuestionId = singleQuestionMapper.updateByPrimaryKeySelective(bankSingleChoiceQue);
        question.setSingleId(singleQuestionId);
        return questionMapper.updateOne(question);
    }

    @Override
    public int deleteByQueId(Integer queId) {
        studentPaperAnswerMapper.deleteByQueId(queId);
        return questionMapper.deleteByQueId(queId);
    }
}
